/**
 * Joystick.h
 * Description: Joystick header file.
 * Authors: Hamish Cumming, Brian Thorne 2008
 *
 * The joystick comprises 5 pull up switches: PB4,6,7,PE2,3.
 * The JOYSTICK task is serviced in joystick.c
 */

#ifndef JOY_H
#define JOY_H

#include "global.h"

/* Constants */
#define PORTB_MASK 0xD0
#define PORTE_MASK 0x0C
#define JOY_DEBOUNCE 1000

/* Pysical Connections */
enum controls {JOY_LEFT=2, JOY_RIGHT=3,JOY_PUSH=4,JOY_UP=6,JOY_DOWN=7};



/* Function Prototypes */
/**
 * Initialize the joystick, set up ports, enable pull up resisters and register task with the kernel.
 */
uint8_t joystick_init(void);

/**
 * Read the joystick
 * A function that reads the 5 switches
 * @return: What button was pressed eg JOY_LEFT, JOY_PUSH
 */
uint8_t joystick_read(void);

/**
 * Poll the joystick
 * @return task exit code
 */
uint8_t joystick_proccess(void);

/**
 * Convert a button code (eg. JOY_LEFT) into a direction.
 *@return The mapped direction
 */
direction_t but2dir(uint8_t con);
#endif
